<?php

/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Cmspage
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */

class Cmspage_Plugin_Core {
	public function onStatistics($event) {
		$table = Engine_Api::_ ()->getDbTable ( 'cmspages', 'cmspage' );
		
		$select = new Zend_Db_Select ( $table->getAdapter () );
		$select->from ( $table->info ( 'name' ), 'COUNT(*) AS count' );
		$event->addResponse ( $select->query ()->fetchColumn ( 0 ), 'pages' );
	}
	
	public function onUserDeleteBefore($event) {
		$payload = $event->getPayload ();
		if ($payload instanceof User_Model_User) {
			// Delete cmspages
			$cmspageTable = Engine_Api::_ ()->getDbtable ( 'cmspages', 'cmspage' );
			$cmspageSelect = $cmspageTable->select ()->where ( 'owner_id = ?', $payload->getIdentity () );
			foreach ( $cmspageTable->fetchAll ( $cmspageSelect ) as $cmspage ) {
				$cmspage->delete ();
			}
		
		// delete images and albums as well
		}
	}
}